#include "AccountUtils.hh"
#include <random>
#include <sstream>
#include <unordered_set>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <sstream>

namespace Bank {
    static std::unordered_set<std::string> usedIds;
    std::string generateUniqueAccountId(int accountType) {
        std::random_device rd;
        std::mt19937 gen(rd());
        std::uniform_int_distribution<> dist4(1000, 9999);

        std::string newId;
        do {
            std::stringstream ss;
            ss << "62" << accountType
            << "-" << dist4(gen)
            << "-" << dist4(gen)
            << "-" << dist4(gen);
            newId = ss.str();
        } while (usedIds.count(newId)); // ensure uniqueness

        usedIds.insert(newId);
        return newId;
    }

    std::string generateUniqueTransactionID() {
        static int txCounter = 0;
        std::stringstream ss;

        auto now = std::chrono::system_clock::now();
        auto time = std::chrono::system_clock::to_time_t(now);

        ss << "TX" << time << "_" << txCounter++;
        return ss.str();
    }

    std::string generateTransactionId() {
            std::ostringstream oss;
            oss << "TX" << std::time(nullptr);
            return oss.str();
    }

    std::string getCurrentDate() {
        std::time_t now = std::time(nullptr);
        std::tm* tm_ptr = std::localtime(&now);

        std::ostringstream oss;
        oss << std::put_time(tm_ptr, "%Y-%m-%d");
        return oss.str();
    }
}
